package org.lanqiao.dxzf.service.admin.impl;

import java.util.List;

import org.apache.ibatis.jdbc.RuntimeSqlException;
import org.lanqiao.dxzf.entity.Role;
import org.lanqiao.dxzf.mapper.admin.RoleMapper;
import org.lanqiao.dxzf.service.admin.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
public class RoleServiceImpl implements RoleService{
	@Autowired
	RoleMapper roleMapper;
	public List<Role> selectAllRoleByAid(Integer aid) {
		// TODO Auto-generated method stub
		return roleMapper.selectAllRoleByAid(aid);
	}
	public List<Role> find(Role role) {
		// TODO Auto-generated method stub
		return roleMapper.find(role);
	}
	@Transactional(rollbackFor=Exception.class)
	public int insertAndaddPriv(Role role, List<Integer> pids) {
		int rid = roleMapper.insert(role);
		int i = roleMapper.addPriv(pids, rid);
		if(rid>0&&i>0) {
			return 1;
		}else {
			throw new RuntimeSqlException("添加时出现异常");
		}
	}

}
